<?php

include '../../db.php';
$connect = pg_connect($connectionString);
if (!$connect) {
    echo "connect : A connection to the server could not be established!";
    return false;
}
$params = array();
array_push($params, pg_escape_string($_POST["id"]));
array_push($params, pg_escape_string(strtoupper($_POST["name"])));
array_push($params, pg_escape_string($_POST["code"]));
array_push($params, pg_escape_string($_POST["type"]));
array_push($params, pg_escape_string($_POST["cost"]));
array_push($params, pg_escape_string($_POST["price"]));
array_push($params, pg_escape_string($_POST["quantity"]));
array_push($params, pg_escape_string($_POST["category_id"]));
array_push($params, pg_escape_string($_POST["subcategory_id"]));
array_push($params, pg_escape_string($_POST["brand_id"]));
array_push($params, pg_escape_string($_POST["model_id"]));
array_push($params, pg_escape_string($_POST["scaffold_id"]));
array_push($params, pg_escape_string($_POST["file_id"]));
array_push($params, pg_escape_string($_POST["position_id"]));
array_push($params, pg_escape_string($_POST["unit_id"]));

$stmt = pg_prepare($connect, "update_warehouse_product", "UPDATE warehouse_product SET name=$2,code=$3,type=$4,cost=$5,price=$6,quantity=$7,category_id=$8,subcategory_id=$9,brand_id=$10,model_id=$11,scaffold_id=$12,file_id=$13,position_id=$14,unit_id=$15 WHERE id = $1 ");

$result = pg_execute($connect, "update_warehouse_product", $params);

if (!$result) {

    die("Error in SQL query: " . pg_last_error());
}

echo "Data successfully inserted!";

pg_free_result($result);
pg_close($connect);